Locator Preference
In DevAssure, the Locator Preference feature empowers users to customize their approach to recording and identifying UI elements in tests. This functionality allows you to prioritize certain types of locators according to your testing needs.
With Locator Preference, users can designate their preferred locators for recording or identifying UI elements.
For instance, you may prioritize tag names or inner text over other options like IDs or CSS selectors. This flexibility ensures that your testing strategy aligns precisely with your preferences and requirements
Ignoring Locators
DevAssure enables users to specify which locators should be ignored during the recording or identification process. By adding a locator to the Ignore Locators list, you can ensure that DevAssure overlooks specific elements that are not relevant to your testing objectives. For example, certain tag names or attributes that do not contribute to testing scenarios can be ignored.
Adding Preferred Locators
You can also specify locators that you want DevAssure to prioritize when recording or identifying UI elements. To do this, add the locator to the Preferred Locators list.
Here are the steps to configure locator preferences in DevAssure:
- Navigate to the Project Preferences in the side navigation menu.
- In the Recorder tab, locate the Locator Preferences section.
- To ignore an attribute, add it to the Ignore Locators list.
- To prioritize an attribute, add it to the top of the Preferred Locators list.
- To ignore custom attributes using a Regex, add the Regex to the CSS Regex section of the Ignore Locators list.
Example
Let's consider the login page of the DevAssure web application to illustrate locator preferences.
By default, the ID is prioritized, resulting in the element "Sign in with Google" being recorded with ID as the primary locator.
Now, let's configure a locator preference to ignore the ID and instead set the title attribute as the preferred locator.
After making this change, when you record the scenario, the title locator will be the primary locator for the element "Sign in with Google" as in the screenshot below.
Precedence of Attributes
When selecting locator attributes, DevAssure follows a specific order of precedence:
- placeholder
- label
- name
- title
- aria-label
- alt
- type
Using Regular Expressions (Regex) to Ignore / Prioritize Attributes
We can also leverage Regex to prioritize / ignore attributes during recording.
For instance, to ignore the data-product attribute, you can add a corresponding Regex expression in the Ignore Locators section.
Before Locator Preference:
Setting Locator Preference:
After Locator Preference:
You can test your regex string at Regex Tester. This is a useful tool to see if your regex pattern matches the text you intend it to.